package com.chunuo.blogs.controller;

import com.chunuo.blogs.entity.Classify;
import com.chunuo.blogs.service.ClassifyService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类
 *
 * @author liujiamiao
 * @email 2544296058@qq.com
 * @date 2020-05-17 12:38
 */
@RestController
public class ClassifyController {

    @Autowired
    private ClassifyService classifyService;

    /**
     * 获取所有分类信息
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/classify")
    public PageInfo findAll(@RequestParam("page")Integer page,@RequestParam("size")Integer size){
        List<Classify> classifies = classifyService.findAll(page,size);
        return new PageInfo(classifies);
    }

    /**
     * 根据id获取详细分类信息
     * @param id
     * @return
     */
    @GetMapping("/classify/{id}")
    public Classify findById(@PathVariable("id") Integer id){
        Classify classify = classifyService.findById(id);
        return classify;
    }

    /**
     * 添加分类的类型
     * @param classify
     * @return
     */
    @PostMapping("/classify")
    public Integer add(@RequestBody Classify classify){
        classifyService.add(classify);
        return 1;
    }

    /**
     * 更新分类（某个类型）
     * @param classify
     * @return
     */
    @PutMapping("/classify")
    public Integer update(@RequestBody Classify classify){
        classifyService.update(classify);
        return 1;
    }

    /**
     * 删除分类（某个类型）
     * @param id
     * @return
     */
    @DeleteMapping("/classify/{id}")
    public Integer delete(@PathVariable("id") Integer id){
        classifyService.delete(id);
        return 1;
    }

}
